package sa.com.sure.ejtimaa.common;


import sa.com.sure.ejtimaa.R;
import sa.com.sure.ejtimaa.R.style;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Handler;
import android.view.View;

public class AppDialogs {

	
	public static int Result_OK  = 0;
	public static int Result_YES  = 1;
	public static int Result_NO  = 2;	
	public static int Result_CANCEL  = 3;		
	
	public static AlertDialog Confirm(Context context,String msg , final Handler handler){
		AlertDialog.Builder builder = new AlertDialog.Builder(context);
		builder.setMessage(msg).setCancelable(false)
		.setPositiveButton(
			context.getString(R.string.Yes), new DialogInterface.OnClickListener() {           
						public void onClick(DialogInterface dialog, int id) {  
							if(handler!=null)             
								handler.sendMessage(handler.obtainMessage(Result_YES));	
							}       
						})
		.setNegativeButton(
				context.getString(R.string.No), new DialogInterface.OnClickListener() {           
						public void onClick(DialogInterface dialog, int id) {
							   if(handler!=null)
									handler.sendMessage(handler.obtainMessage(Result_NO));
								dialog.cancel();           
							}       
						});
		AlertDialog alert = builder.create();		
		alert.show();
		
		return alert;
	}
	
	public static AlertDialog Alert(Context context,String title,String msg , final Handler handler){
		
		AlertDialog alert = new AlertDialog.Builder(context).create();
		alert.setTitle(title);
		alert.setMessage(msg);
		alert.setButton(context.getString(R.string.Ok), new DialogInterface.OnClickListener() {
		   public void onClick(DialogInterface dialog, int which) {
			   if(handler!=null)   
			   {
					handler.sendMessage(handler.obtainMessage(Result_OK));
					dialog.cancel();
			   } 
		   }
		});	
		
		alert.show();
				
		return alert;
	}
	
	
	public static void Dialog(Context context , String title,  final View view , DialogInterface.OnClickListener OnPositiveClick , DialogInterface.OnClickListener OnNegativeClick)
	{			
		  	 Builder _Dialog = null;
	    	
    	    _Dialog = new AlertDialog.Builder(context,R.style.RightJustifyTheme);
    	    _Dialog.setTitle(title);
    	    _Dialog.setView(view);
    	    _Dialog.setPositiveButton(context.getString(R.string.Ok), OnPositiveClick);
    	    _Dialog.setNegativeButton(R.string.Cancel, OnNegativeClick);
    	    
    	    _Dialog.show();	    	 

	}
	
	
	public static ProgressDialog ProgressDialog(Context context,int min ,int max ,String title , String message){
		
		ProgressDialog dialog = new ProgressDialog(context,style.RightJustifyTheme);
        dialog.setCancelable(false);
        dialog.setMessage(context.getString(R.string.Synchronize));
        dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        dialog.setProgress(0);
        dialog.setMax(max);        
        dialog.show();
        
        return dialog;
	}
	
	public static ProgressDialog ProgressWaitingDialog(Context context)
	{	
		 return ProgressWaitigDialog(context,context.getString(R.string.PleaseWati), context.getString(R.string.RetrievingData));
	}
	
	public static ProgressDialog ProgressWaitigDialog(Context context,String title , String message){
		
		ProgressDialog m_ProgressDialog = new ProgressDialog(context, style.RightJustifyTheme);
        m_ProgressDialog.setTitle(title);
        m_ProgressDialog.setMessage(message);
        m_ProgressDialog.setCancelable(false);
        m_ProgressDialog.show();
        return m_ProgressDialog;  
	}

}
